package com.kk.controller;

import com.kk.annotation.OperationLog;
import com.kk.common.Result;
import com.kk.enums.OperationType;
import com.kk.pojo.vo.MenuTreeVO;
import com.kk.service.SysMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author kl
 * @version 1.0
 * @description: 菜单相关的controller
 * @date 2025/11/5 上午9:32
 */
@RestController
@RequestMapping("/menus")
@RequiredArgsConstructor
public class SysMenuController {

    private final SysMenuService sysMenuService;

    /**
     * 获取全部菜单并返回给前端，这个是不需要搜索参数和分页的，但是需要鉴权
     * @return
     */
    @OperationLog(
            module = "menus",
            type = OperationType.QUERY,
            description = "查询所有菜单"
    )
    @GetMapping("/all")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result<List<MenuTreeVO>> getMenus(){
        return Result.success(sysMenuService.getAllMenus());
    }

}
